package com.cmas.platform.controller;

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import com.aidex.common.annotation.DataSource;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.TableDataInfo;
import com.aidex.common.core.page.PageDomain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aidex.common.enums.BusinessType;
import com.aidex.common.enums.DataSourceType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.common.core.controller.BaseController;
import com.aidex.framework.cache.DictUtils;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.cmas.platform.domain.NotificationUser;
import com.cmas.platform.service.NotificationUserService;


/**
 * 通知公告用户阅读表Controller
 *
 * @author su
 * @email 1218819874@qq.com
 * @date 2024-05-19
 */
@DataSource(value = DataSourceType.SLAVE)
@RestController
@RequestMapping("/platform/notificationUser")
public class NotificationUserController extends BaseController {

    @Autowired
    private NotificationUserService notificationUserService;

    /**
     * 查询通知公告用户阅读表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:list')")
    @GetMapping("/list")
    public R<TableDataInfo> list(NotificationUser notificationUser) {
        startPage();
        List<NotificationUser> list = notificationUserService.selectNotificationUserList(notificationUser);
        return R.data(getDataTable(list));
    }

    /**
     * 获取通知公告用户阅读表详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:query')")
    @GetMapping(value = "/{id}")
    public R<NotificationUser> detail(@PathVariable("id") String id) {
        return R.data(notificationUserService.getById(id));
    }

    /**
     * 新增通知公告用户阅读表
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:add')")
    @Log(title = "通知公告用户阅读表", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated NotificationUser notificationUser) {
        return R.data(notificationUserService.save(notificationUser));
    }

    /**
     * 修改通知公告用户阅读表
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:edit')")
    @Log(title = "通知公告用户阅读表", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated NotificationUser notificationUser) {
        return R.data(notificationUserService.updateById(notificationUser));
    }

    /**
     * 删除通知公告用户阅读表
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:remove')")
    @Log(title = "通知公告用户阅读表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.data(notificationUserService.removeByIds(Arrays.asList(ids)));
    }


    /**
     * 导出通知公告用户阅读表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:notificationUser:export')")
    @Log(title = "通知公告用户阅读表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(NotificationUser notificationUser) {
        List<NotificationUser> list = notificationUserService.selectNotificationUserList(notificationUser);
        ExcelUtil<NotificationUser> util = new ExcelUtil<NotificationUser>(NotificationUser.class);
        return util.exportExcel(list, "通知公告用户阅读表数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }


    // ***用户系统位置戳****

    /**
     * 阅读公告
     */

    @Log(title = "通知公告用户阅读表", businessType = BusinessType.INSERT)
    @PostMapping("/readNotification")
    public R readNotification(@RequestBody List<String> ids) {
        return R.data(notificationUserService.readNotification(ids));
    }
}
